package com.sunkyc.commons.validation;

import com.sunkyc.commons.annotation.IsPhoneNumber;
import com.sunkyc.commons.utils.CommonValidationUtils;
import org.apache.commons.lang3.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class IsPhoneValidation implements ConstraintValidator<IsPhoneNumber, String> {
    @Override
    public void initialize(IsPhoneNumber constraintAnnotation) {
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        if (StringUtils.isBlank(value)) {
            return false;
        } else {
            return CommonValidationUtils.isPhone(value);
        }
    }
}
